$dbw->commit( __METHOD__ );
}
+ // purge cache
+ $this->reset();
+
return $success;
}
+ /**
+ * Purges the internal and external cache of the site list, forcing the list
+ * of sites to be re-read from the database.
+ *
+ * @since 1.21
+ */
+ public function reset() {
+ // purge cache
+ $cache = wfGetMainCache();
+ $cache->delete( $this->getCacheKey() );
+ $this->sites = null;
+ }
+
/**
* @since 1.21
*
return $this->getSites()->getGroup( $group );
}
-}
\ No newline at end of file
+}
$expectedSites = TestSites::getSites();
TestSites::insertIntoDb();
- $sitesTable = SiteSQLStore::newInstance();
+ $store = SiteSQLStore::newInstance();
- $sites = $sitesTable->getSites();
+ $sites = $store->getSites();
$this->assertInstanceOf( 'SiteList', $sites );
}
public function testSaveSites() {
- $sitesTable = SiteSQLStore::newInstance();
+ $store = SiteSQLStore::newInstance();
$sites = array();
$site->setLanguageCode( 'nl' );
$sites[] = $site;
- $this->assertTrue( $sitesTable->saveSites( $sites ) );
+ $this->assertTrue( $store->saveSites( $sites ) );
- $site = $sitesTable->getSite( 'ertrywuutr', 'nocache' );
+ $site = $store->getSite( 'ertrywuutr' );
$this->assertInstanceOf( 'Site', $site );
$this->assertEquals( 'en', $site->getLanguageCode() );
- $site = $sitesTable->getSite( 'sdfhxujgkfpth', 'nocache' );
+ $site = $store->getSite( 'sdfhxujgkfpth' );
$this->assertInstanceOf( 'Site', $site );
$this->assertEquals( 'nl', $site->getLanguageCode() );
}
+ public function testReset() {
+ $store = SiteSQLStore::newInstance();
+
+ // initialize internal cache
+ $this->assertGreaterThan( 0, $store->getSites()->count() );
+
+ // Clear actual data. Will not purge the internal cache in store2.
+ $dbw = wfGetDB( DB_MASTER );
+ $dbw->delete( 'sites', '*', __METHOD__ );
+ $dbw->delete( 'site_identifiers', '*', __METHOD__ );
+
+ // sanity check: $store2 should have a stale cache now
+ $this->assertNotNull( $store->getSite( 'enwiki' ) );
+
+ // purge cache
+ $store->reset();
+
+ // ...now the internal cache of $store2 should be updated and thus empty.
+ $site = $store->getSite( 'enwiki' );
+ $this->assertNull( $site );
+ }
+
}